<div id="container-wrapper">
<div id="container">
  <div id="scroll-down-target"></div> <!-- This is Flexslider scroll down button target -->


<!-- Begin notifications -->
<div id="notification-fixed">
  <div id="notification"></div>
</div>
<!-- End notifications -->





<!-- Begin cart "Close" button mobile devices fix script -->
<script type="text/javascript">
    $(function() {
        $('.success .close, .warning .close, .attention .close, .information .close').live('click', function (event) {
            event.preventDefault();
            $('#notification').removeClass('active');
        });
    });
</script>
<!-- End cart "Close" button mobile devices fix script -->

 
<div id="content">  <div class="breadcrumb">
        <a href="#">Home</a>
         » <a href="#m">Shopping Cart</a>
      </div>
  <h1>Shopping Cart        
      </h1>
  <form action="#" method="post" enctype="multipart/form-data">
    <div class="cart-info">
      <table>
          
        <thead>
          <tr>
            <td class="image">Hình</td>
            <td class="name">Tên sản phẩm</td>
            <td class="name">Màu sắc</td>
            <td class="name">Size</td>
            <td class="quantity">Số lượng</td>
            <td class="price">Giá</td>
            <td class="total">Tổng</td>
          </tr>
        </thead>
         
        <?php
            if (isset($_SESSION['daySoLuong'])){
                reset($_SESSION['daySoLuong']);
                reset($_SESSION['dayMaSP']);
                reset($_SESSION['dayTenSP']);
                reset($_SESSION['dayMoTa']);
                reset($_SESSION['dayDonGia']);
                reset($_SESSION['dayUrlHinh']);
                reset($_SESSION['daySize']);
                reset($_SESSION['dayMau']);
                while (key($_SESSION['daySoLuong']) != null) {
                    $idSP = key($_SESSION['daySoLuong']);
                    $mota = current($_SESSION['dayMoTa']);
                    $tensp = current($_SESSION['dayTenSP']);
                    $soluong = current($_SESSION['daySoLuong']);
                    $dongia = current($_SESSION['dayDonGia']);
                    $urlhinh = current($_SESSION['dayUrlHinh']);
                    $size = current($_SESSION['daySize']);
                    $mau_id = current($_SESSION['dayMau']);
                    if ($soluong > 0) {
                        ?>
        <tbody>
                                <tr>
            <td class="image">              <a href=""><img width="100px" src="<?php echo $urlhinh; ?>"  title=""></a>
              </td>
            <td class="name" width="300px"><a href=""><?php echo $tensp; ?></a>
                            <div>
                                <small><?php echo $mota; ?></small>
                                              </div>
                            
              </td>
            <td class="name">
                  <?php
                        $chitietmau = $tc->getDetailMau($mau_id);
                        $row_mau = mysql_fetch_assoc($chitietmau);
                        $_SESSION['dayMauHinh'][$idSP] = "http://lahava.vn/" . $row_mau['hinh'];
                        echo $row_mau['ten'];
                   ?>
              </td>
              <td class="name">
                  <?php
                         echo $size; 
                   ?>
              </td>
            <td class="quantity">
                <div class="cart-qty">
                    <span>Số lượng:</span><span id="soluong_<?php echo $idSP; ?>"><?php echo $soluong; ?></span> &nbsp;
                    <img src="static/cong.png" idSP="<?php echo $idSP; ?>" class="nut_cong" soluong="<?php echo ($soluong + 1); ?>"  />
                    <img src="static/tru.png" idSP="<?php echo $idSP; ?>" class="nut_tru" soluong="<?php echo ($soluong - 1); ?>" />

                </div>
              </td>
            <td class="price"><?php echo number_format($dongia)?>VNĐ </td>
            <td class="total"><?php echo number_format($_SESSION['tien_sp'][$idSP]); ?></td>
          </tr>
                            </tbody>
          <?php
                }
                next($_SESSION['daySoLuong']);
                next($_SESSION['dayDonGia']);
                next($_SESSION['dayMaSP']);
                next($_SESSION['dayUrlHinh']);
                next($_SESSION['dayMau']);
                next($_SESSION['daySize']);
                ?>
        <?php } }?>
      </table>
    </div>
  </form>
    
  
  
    <div class="cart-total">
    <table id="total">
            <tbody>
           
            
            <tr>
        <td class="right"><b>Thành tiền:</b></td>
        <td class="right"><?php echo $tong=number_format($_SESSION['tong_tien']) ; ?></td>
      </tr>
          </tbody></table>
  </div>
  <div class="buttons">
    <div class="right"><a href="thanh-toan.html" class="button">Tính tiền</a></div>
    <div class="center"><a href="index.php" class="button">Lựa đồ típ</a></div>
  </div>
  </div>

</div><!-- End container //-->
</div><!-- End container wrapper //-->

<script type="text/javascript">    
function addcommas(nstr) {
    nstr += '';
    var x = nstr.split('.');
    var x1 = x[0];
    var x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
    $(function() {
        $('.nut_cong').click(function() {
            var idSP = $(this).attr('idSP');
            var soluong = $(this).attr('soluong');
            if (parseInt(soluong) < 11) {
                $.post('ajax/process_cart.php', {sp_id: idSP, update: 'update', soluong: soluong, action: 'update'}, function(data) {
                    var arrRes = JSON.parse(data);
                    $('#tien_' + idSP).html(addcommas(arrRes.tien_sp));
                    $('#total_price').html(addcommas(arrRes.tong_tien));
                    $('#so_sp_gio_hang').html(arrRes.tong_so_sp);
                    $('#soluong_' + idSP).html(soluong);
                    $('img.nut_cong[idSP=' + idSP + ']').attr('soluong', parseInt(soluong) + 1);
                    $('img.nut_tru[idSP=' + idSP + ']').attr('soluong', parseInt(soluong) - 1);
                    if (arrRes.tong_tien == 0)
                        $('#thanh_toan').hide();
                });
            }
        });
        $('.nut_tru').click(function() {
            var idSP = $(this).attr('idSP');
            var soluong = $(this).attr('soluong');
            if (parseInt(soluong) > -1) {
                $.post('ajax/process_cart.php', {sp_id: idSP, update: 'update', soluong: soluong, action: 'update'}, function(data) {
                    var arrRes = JSON.parse(data);
                    $('#tien_' + idSP).html(addcommas(arrRes.tien_sp));
                    $('#total_price').html(addcommas(arrRes.tong_tien));
                    $('#so_sp_gio_hang').html(arrRes.tong_so_sp);
                    if (soluong == 0) {
                        $('#dong_' + idSP).hide();
                        $('#empty_cart_button').hide();
                    } else {
                        $('#soluong_' + idSP).html(soluong);
                        $('img.nut_cong[idSP=' + idSP + ']').attr('soluong', parseInt(soluong) + 1);
                        $('img.nut_tru[idSP=' + idSP + ']').attr('soluong', parseInt(soluong) - 1);
                    }
                    if (arrRes.tong_tien == 0)
                        $('#thanh_toan').fadeOut(1000);
                });
            }
        });
        $('.xoa_sp').click(function(){
		var idSP = $(this).attr('idSP');		
		
		$.post('ajax/process_cart.php',{sp_id:idSP,action:'remove'},function(data){					
			var arrRes = JSON.parse(data);		
			$('#tien_'+ idSP).html(addcommas(arrRes.tien_sp));
			$('#total_price').html(addcommas(arrRes.tong_tien));	
			$('#so_sp_gio_hang').html(arrRes.tong_so_sp);				
			$('tr#dong_'+ idSP).hide();									
			if(arrRes.tong_tien==0) $('#thanh_toan').fadeOut(1000);					
		});
		
	});
             
    });
</script>